﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="pragma" content="no-cache">  <!-- HTTP 1.1 -->
    <meta http-equiv="cache-control" content="no-cache,must-revalidate">  <!-- HTTP 1.0 -->
    <meta name="renderer" content="webkit|ie-comp|ie-stand"/> <!--优先级：极速模式，兼容模式，IE模式-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <title>扬州房产测绘业务管理系统</title>
    <link rel="stylesheet" type="text/css" href="../../libs/jeasyui-181/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../libs/jeasyui-181/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../../libs/jeasyui-181/themes/color.css">
    <link rel="stylesheet" type="text/css" href="../../css/common.css">
    <script type="text/javascript" src="../../libs/jeasyui-181/jquery.min.js"></script>
    <script type="text/javascript" src="../../libs/jeasyui-181/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../libs/thUtil.js"></script>
    <script type="text/javascript" src="../../libs/valid.js"></script>
    <script type="text/javascript">
        var mainGrid = new UserContol();

        $(function () {
            mygrid.init();
            ajax.bindEvent();
        });


        var ajax = {
            getList: function (param, success) {
                Network.connect(window.api.navEventGetPageViewByNavId, 'POST', {navigationId: UrlParm.parm('id')}, function (res) {
                    if (res.code === ResponseCode.OK) {
                        success(res.data);
                    }
                });
            },
            getOne: function (param, success) {
                Network.connect(window.api.userSelectView, 'POST', param, function (res) {
                    if (res.code === ResponseCode.OK) {
                        success(res.data);
                    }
                });
            },
            insert: function () {
                dlg = window.parent.$.hDialog({
                    href: window.router.btnForm + '?n=' + Math.random(),
                    title: '新增按钮',
                    width: 700,
                    height: 400,
                    onLoad: function () {
                        //赋值菜单id
                        window.parent.$('#navigationId').val(UrlParm.parm('id'));
                    },
                    submit: function () {
                        var isValid = window.parent.$('#form').form("validate");
                        if (isValid) {
                            var formData = window.parent.$("#form").serializeJson();
                            Network.connect(window.api.navEventUpdateView, 'POST', formData, function (res) {
                                if (res.code === ResponseCode.OK) {
                                    Tools.show(res.message);
                                    dlg.dialog('close');
                                    mygrid.reload();
                                }
                            });
                        }
                    }
                });
            },
            update: function () {
                var rows = $('#mainGrid').datagrid("getSelections");
                if (rows.length === 0) {
                    Tools.alert('请选择需要修改的数据。');
                    return;
                }
                dlg = window.parent.$.hDialog({
                    href: window.router.btnForm + '?n=' + Math.random(),
                    title: '修改按钮',
                    width: 920,
                    height: 700,
                    onLoad: function () {
                        Network.connect(window.api.navEventSelectView,"POST",{id:rows[0].id},function (res) {
                            if (res.code===ResponseCode.OK){
                                window.parent.$('#form').form('load', res.data);
                            }
                        });

                    },
                    submit: function () {
                        var isValid = window.parent.$('#form').form("validate");
                        if (isValid) {
                            var formData = window.parent.$("#form").serializeJson();
                            Network.connect(window.api.navEventUpdateView, 'POST', formData, function (res) {
                                if (res.code === ResponseCode.OK) {
                                    Tools.show(res.message);
                                    dlg.dialog('close');
                                    mygrid.reload();
                                }
                            });
                        }
                    }
                });
            },
            delete: function () {
                var rows = $('#mainGrid').datagrid("getSelections");
                if (rows.length === 1) {
                    Tools.confirm('是否确定删除该数据？', function (result) {
                        if (result) {
                            Network.connect(window.api.navEventDeleteView, 'POST', {id: rows[0].id}, function (res) {
                                if (res.code === ResponseCode.OK) {
                                    Tools.show('删除成功');
                                    mygrid.reload();
                                }
                            });
                        }
                    });
                }
                else {
                    Tools.alert('请选择需要删除的数据。');
                }
            },
            bindEvent:function () {
                $('#delete').linkbutton({onClick:ajax.delete});
                $('#insert').linkbutton({onClick:ajax.insert});
                $('#update').linkbutton({onClick:ajax.update});
            }

        };
        var mygrid = {
            init: function () {
                mainGrid.dataGrid.id = 'mainGrid';
                mainGrid.dataGrid.idField = 'id';
                mainGrid.dataGrid.sortName = 'order';
                mainGrid.dataGrid.sortOrder = 'asc';
                mainGrid.dataGrid.toolbar = '#toolbar';
                mainGrid.dataGrid.onLoadSuccess = function (data) {
                    if (data.total === 0)
                        setEmptyData($(this));
                };
                mainGrid.dataGrid.loader = function (param, success, error) {
                    $('#mainGrid').datagrid('clearSelections');
                    ajax.getList(param, success);
                };
                mainGrid.dataGrid.columns = [[
                    {field: 'id', title: '主键', hidden:true},
                    {
                        field: 'name',
                        title: '名称',
                        halign: 'center',
                        align: 'center',
                        width: 120
                    },
                    {field: 'code', title: '编码', halign: 'center', align: 'center', width: 120},
                    {field: 'orderNo', title: '排序', halign: 'center', align: 'center', width: 120},
                    {field: 'description', title: '描述', halign: 'center', align: 'center', width: 200}
                ]];
                mainGrid.InitdataGrid();
            },
            reload: function () {
                $('#mainGrid').datagrid('reload');
            },
            selectRow: function () {
                return $('#mainGrid').datagrid('getSelected');
            }
        };

    </script>

</head>
<body>
<div class="container-wrap" style="width: 86%">
    <div id="toolbar">
        <div class="sreach fixed">
            <div class="bar-btn">
                <a id="insert" href="#" class="easyui-linkbutton insert">新增</a>
                <a id="update" href="#" class="easyui-linkbutton update">修改</a>
                <a id="delete" href="#" class="easyui-linkbutton delete">删除</a>
            </div>
        </div>
    </div>
    <div id="mainGrid"></div>
</div>

</body>
</html>